/**
 *
 */
package com.wude.guild.imageutil.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.wude.guild.imageutil.R;
import com.wude.guild.imageutil.face.PhotoFace;

/**
 * 拍照、相册弹窗
 */
public class PhotoDialog extends Dialog implements
        View.OnClickListener {
    private PhotoFace face;
    /**
     * 拍照
     */
    private TextView takePhoto;
    /**
     * 本地上传
     */
    private TextView cellPhoto;
    /**
     * 取消
     */
    private TextView cancel;

    public PhotoDialog(Context context, PhotoFace face) {
        super(context);
        this.face = face;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);// 去标题栏
        setContentView(R.layout.photo_dialog_layout);
        // 宽度充满整个手机屏
        Window window = this.getWindow();
        window.setBackgroundDrawableResource(R.color.window_color);
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.FILL_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        //在手机屏幕下方
        window.setAttributes(lp);
        window.setGravity(Gravity.BOTTOM);
        // View初始设定
        takePhoto = findViewById(R.id.takePhoto_photoDialog);
        cellPhoto = findViewById(R.id.cellPhoto_photoDialog);
        cancel = findViewById(R.id.cancel_photoDialog);
        takePhoto.setOnClickListener(this);
        cellPhoto.setOnClickListener(this);
        cancel.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int i = view.getId();
        if (i == R.id.takePhoto_photoDialog) {
            face.takePhoto();
            this.dismiss();

        } else if (i == R.id.cellPhoto_photoDialog) {
            face.cellPhoto();
            this.dismiss();

        } else if (i == R.id.cancel_photoDialog) {
            this.dismiss();

        } else {
        }
    }
}
